import {
  Toast
} from "vant";
import { scrollMixin } from "../../../utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      list: [],
      transferPop: false,
      money: '',//获得余额
      niuUid: '',//转出换牛id
      niuzheng: '',//转出牛证
      niuzhengShouxu: '',//牛证手续费
      huanhuo: '',//转出换货值
      moneyShouxu: 0,//现金手续费
      listId: '',//兑换列表id
      page: 1,
      total: 0,
      isLoadMore: true
    };
  },

  mounted() {},

  created() {
    if (!localStorage.getItem("uid")) {
      this.$router.push(this.fun.getUrl("member"));
      return
    }

      this.getList();

  },

  methods: {
    niuUidChange(e){
      console.log(this.niuUid,'换牛id发生改变')
      $http.post("HuanNiuJiuji.getCharge", {
        hn_uid: this.niuUid
      }, "加载中").then(res => {
        console.log(res,'手续费')
        if (res.result == 1) {
          this.moneyShouxu = res.data.charge
        }else {
          this.moneyShouxu = 0
          Toast(res.msg)

        }
      })
    },
    openPopup(data) {
      this.listId = data.id;
      this.niuzheng = data.niuzheng;
      this.niuzhengShouxu = data.niuzheng_shouxu;
      this.huanhuo = data.huanhuozhi;
      this.money = data.balance;
      this.transferPop = true;
    },
    confirmPop(){
        // this.transferPop = false
        if(this.niuUid == ''){
          Toast('换牛科技ID号不能为空')
          return
        }
        if(this.moneyShouxu == 0){
          Toast('手续费不正确')
          return
        }
        $http.post("HuanNiuJiuji.applyDestroy", {
          id: this.listId,
          hn_uid: this.niuUid,
          charge: this.moneyShouxu
        }, "加载中").then(res => {
          console.log(res,'手续费')
          if (res.result == 1) {
            this.niuUid = '';
            this.moneyShouxu = 0;
            this.listId = '';
            this.transferPop = false;
            this.page = 1;
            this.list = []
            this.getList();
            Toast('成功')
          }else {
            Toast(res.msg)
  
          }
        })
    },
    cancelPop(){
        this.transferPop = false
    },
    getList() {
      $http.post("HuanNiuJiuji.destroyList", {
        uid: localStorage.getItem("uid"),
        page: this.page
      }, "加载中").then(res => {
        // if (res.result == 1) {
        //   this.list = res.data.data
          
        // }
        // console.log(res);
        if (res.result == 1) {
          console.log(res, 'shuju_list')
          var nextPageData = res.data.data;
          this.list = [...this.list, ...nextPageData];
          this.total = res.data.last_page;
          this.isLoadMore = true;

        } else {
          this.isLoadMore = false;
        }
      })
    },
     //获取更多数据
     getMoreData() {
      console.log("列表", this.isLoadMore);
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total) {
          Toast('到底了')
        return;
      } else {
        this.page += 1;
        this.getList();
      }
    },
  }
};